<div class="doc-item" id="doc-1076"><h2 class="doc-item-name">normalize<span class="namespace">(clojure.contrib.probabilities.finite-distributions)</span></h2><ul class="var-arglists"><li>(<span class="var-name">normalize</span>  weights)</li></ul><div class="var-docstring"><p>Convert a weight map (e.g. a map of counter values) to a distribution
   by multiplying with a normalization factor. If the map has a key
   :total, its value is assumed to be the sum over all the other values and
   it is used for normalization. Otherwise, the sum is calculated
   explicitly. The :total key is removed from the resulting distribution.</p></div><div class="var-source"><pre>; clojure/contrib/probabilities/finite_distributions.clj:72
(defn normalize
  [weights]
  (let [total (:total weights)
	w (dissoc weights :total)
	s (/ 1 (if (nil? total) (reduce + (vals w)) total))]
    (scale-by w s)))</pre></div><div class="license"><p>Copyright (c) Rich Hickey. All rights reserved.</p><p>The use and distribution terms for this software are covered by the <a href="http://opensource.org/licenses/eclipse-1.0.php">Eclipse Public License 1.0</a>, which can be found in the file
          epl-v10.html at the root of this distribution. By using this software
          in any fashion, you are agreeing to be bound by the terms of this
          license. You must not remove this notice, or any other, from this
          software.</p></div></div>